<template>
    <div>
        <div class="btn-panel">
            <el-button size="small" type="danger" icon="el-icon-delete" @click="del">删除</el-button>
          <el-button size="small" type="primary" icon="el-icon-search" @click="detail">详情</el-button>
        </div>
        <r-table ref="mutipleTable" :tableData="tableData" :tableCols="tableCols">
            <template slot="slot_post" slot-scope="scope">
                {{scope.data.post.name}}
            </template>
            <template slot="slot_company" slot-scope="scope">
                {{scope.data.company.name}}
            </template>
            <template slot="slot_resume" slot-scope="scope">
                {{scope.data.resume.name}}
            </template>
            <template slot="slot_status" slot-scope="scope">
                <!--0待查看|1已查看|2有意向|3不合适-->
                <el-tag v-if="scope.data.status == 0">待查看</el-tag>
                <el-tag type="success" v-if="scope.data.status == 1">已查看</el-tag>
                <el-tag type="warning" v-if="scope.data.status == 2">有意向</el-tag>
                <el-tag type="danger" v-if="scope.data.status == 3">不合适</el-tag>
            </template>
        </r-table>
        <r-pagination :page="page" :total="total" @handleCurrentChange="handleCurrentChange"></r-pagination>
      <el-drawer
          title="简历详情"
          size='50%'
          :visible.sync="drawer">
        <ResumeDetail v-if="drawer" :id="selectedId"></ResumeDetail>
      </el-drawer>
    </div>
</template>

<script>
    import {student_send} from "@/api/send";
    import {message} from "@/utils/message";
    import {del} from '@/api/send'
    import RTable from "@/components/RTable";
    import RPagination from "@/components/RPagination";
    import ResumeDetail from "../../components/ResumeDetail";
    export default {
        name:"StudentSend",
        components: {RPagination,RTable,ResumeDetail},
        data(){
            return{
                total:0,
                page:1,
                drawer:false,
                selectedId:0,
                tableData:[],
                tableCols:[
                    {prop:'id', label:'ID', width:80},
                    {prop:'postId', label:'职位',slot:'slot_post'},
                    {prop:'companyId', label:'公司',slot:'slot_company'},
                    {prop:'resumeId', label:'简历名称',slot:'slot_resume'},
                    {prop:'status', label:'状态',slot:'slot_status'},
                    {prop:'sendDate', label:'投递日期'},
                ],
            }
        },
        mounted() {
            this.list({})
        },
        methods:{
            handleCurrentChange(val){
                this.page = val;
                let params= {};
                params.page = this.page
                this.list(params);
            },
            list(params){
                student_send(params).then(res=>{
                    this.tableData = res.data;
                    this.total = res.total;
                })
            },
          detail(){
            let selection = this.$refs['mutipleTable'].selection;
            if(selection.length==1){
              this.selectedId = selection[0].resumeId
              this.drawer= true;
            }else{
              message.warning('请选择一条数据查看')
            }
          },
            del(){
                let selection = this.$refs['mutipleTable'].selection;
                if(selection.length>0){
                    this.$confirm('确定要删除吗','删除提示').then(()=>{
                        let arr = selection.map(item=>item.id);
                        let ids = arr.join(',');
                        del(ids).then(res=>{
                            message.success(res.msg);
                            this.list({})
                        })
                    }).catch(()=>{})
                }else{
                    message.warning('请选择要删除的数据')
                }
            }
        }
    }
</script>

<style scoped>

</style>